package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import org.come.mouslisten.TeamPostMessageListener;
import org.come.until.CutButtonImage;
import org.come.until.LimitNumTextArea;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.TeamPanelBtn;
import com.tool.tcpimg.UIUtils;

 

/**
 * 发布队伍信息窗口 编号：19
 * 
 * @author HGC<br>
 * @time 2019年12月30日 上午9:24:27<br>
 * @class 类名:TeamPostMessageJpanel<br>
 */
public class TeamPostMessageJpanel extends JPanel {
    /**
     * 字段名:labArrRestrains 强克类型选项框 7个<br>
     * 字段名:labArrTask 任务类型选项框 3个<br>
     * 字段名:labArrTeam 任务类型选项框 5个<br>
     * 
     * @time 2019年12月30日 上午9:33:53<br>
     */
    private JLabel[] labArrRestrains, labArrTask, labArrTeam;

    private LimitNumTextArea sendBelTextArea;

    /**
     * 字段名:btnIssue 立即发布<br>
     * 
     * @time 2019年12月30日 上午10:47:25<br>
     */
    private TeamPanelBtn btnIssue;

    private String[] strRestrains, strTask;

    public TeamPostMessageJpanel() {
        this.setPreferredSize(new Dimension(402, 316));
        this.setOpaque(false);
        this.setLayout(null);

        // 关闭按钮事件
        FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 19);
        offBtn.setBounds(402 - 40, 10, 25, 25);
        this.add(offBtn);

        getLabArrRestrains();
        getLabArrTask();
        getLabArrTeam();
        getSendBelTextArea();
        getBtnIssue();

    }

    /**
     * 获取选中的类型
     * 
     * @time 2019年12月30日 上午10:55:48<br>
     * @param type
     *            1强克类型 2任务类型
     * @return
     */
    public String getChooseRestrainStr(int type) {
        if (type == 1) {
            for (int i = 0; i < labArrRestrains.length; i++) {
                if (labArrRestrains[i].getIcon() != null) {
                    return getStrRestrains()[i];
                }
            }
        } else {
            for (int i = 0; i < labArrTask.length; i++) {
                if (labArrTask[i].getIcon() != null) {
                    return getStrTask()[i];
                }
            }
        }
        return null;
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon == null) {
            icon = new ImageIcon("inkImg/newbackground/B210.png");
        }
        g.drawImage(icon.getImage(), 0, 0, 399, 311, null);
    }

    public JLabel[] getLabArrRestrains() {
        if (labArrRestrains == null) {
            labArrRestrains = new JLabel[7];
            for (int i = 0; i < labArrRestrains.length; i++) {
                labArrRestrains[i] = new JLabel();
                labArrRestrains[i].addMouseListener(new TeamPostMessageListener(1, this, i));
                labArrRestrains[i].setBounds(124 + i % 4 * 64, 31 + i / 4 * 24, 18, 18);
                this.add(labArrRestrains[i]);
            }
            labArrRestrains[0].setIcon(CutButtonImage.getImage("skin/8100226/button/B214.png", -1, -1));
        }
        return labArrRestrains;
    }

    public void setLabArrRestrains(JLabel[] labArrRestrains) {
        this.labArrRestrains = labArrRestrains;
    }

    public JLabel[] getLabArrTask() {
        if (labArrTask == null) {
            labArrTask = new JLabel[3];
            for (int i = 0; i < labArrTask.length; i++) {
                labArrTask[i] = new JLabel();
                labArrTask[i].setBounds(127 + i * 64, 83, 13, 13);
                labArrTask[i].addMouseListener(new TeamPostMessageListener(2, this, i));
                this.add(labArrTask[i]);
            }
            labArrTask[0].setIcon(CutButtonImage.getImage("skin/8100226/button/B88.png", -1, -1));
        }
        return labArrTask;
    }

    public void setLabArrTask(JLabel[] labArrTask) {
        this.labArrTask = labArrTask;
    }

    public JLabel[] getLabArrTeam() {
        if (labArrTeam == null) {
            labArrTeam = new JLabel[5];
            for (int i = 0; i < labArrTeam.length; i++) {
                labArrTeam[i] = new JLabel("不限", SwingConstants.CENTER) {
                    private ImageIcon icon;

                    @Override
                    protected void paintComponent(Graphics g) {
                        if (getIcon() == null) {
                            if (icon == null) {
                                icon = CutButtonImage.getImage("inkImg/old/2/S158.png", -1, -1);
                            }
                            g.drawImage(icon.getImage(), 1, 1, 39, 39, null);
                        }
                        super.paintComponent(g);

                    }
                };
                labArrTeam[i].setFont(UIUtils.TEXT_FONT1);
                labArrTeam[i].setForeground(Color.white);
                labArrTeam[i].addMouseListener(new TeamPostMessageListener(3, this, i));
                labArrTeam[i].setBounds(129 + i * 50, 111, 41, 41);
                this.add(labArrTeam[i]);
            }
        }
        return labArrTeam;
    }

    public void setLabArrTeam(JLabel[] labArrTeam) {
        this.labArrTeam = labArrTeam;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

    public LimitNumTextArea getSendBelTextArea() {
        if (sendBelTextArea == null) {
            sendBelTextArea = new LimitNumTextArea(50);
            sendBelTextArea.setLineWrap(true);
            sendBelTextArea.setOpaque(false);
            sendBelTextArea.setForeground(Color.white);
            sendBelTextArea.setBounds(128, 165, 241, 91);
            sendBelTextArea.setCaretColor(Color.white);
            this.add(sendBelTextArea);
        }
        return sendBelTextArea;
    }

    public void setSendBelTextArea(LimitNumTextArea sendBelTextArea) {
        this.sendBelTextArea = sendBelTextArea;
    }

    public TeamPanelBtn getBtnIssue() {
        if (btnIssue == null) {
            btnIssue = new TeamPanelBtn("skin/8100226/newbutton/B22.png", 1, "立即发布", UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16,
                    this);
            btnIssue.setBounds(140, 268, 99, 24);
            this.add(btnIssue);
        }
        return btnIssue;
    }

    public void setBtnIssue(TeamPanelBtn btnIssue) {
        this.btnIssue = btnIssue;
    }

    public String[] getStrRestrains() {
        if (strRestrains == null) {
            strRestrains = new String[] { "不限", "克金", "克木", "克水", "克火", "克土", "无属性" };
        }
        return strRestrains;
    }

    public void setStrRestrains(String[] strRestrains) {
        this.strRestrains = strRestrains;
    }

    public String[] getStrTask() {
        if (strTask == null) {
            strTask = new String[] { "日常", "PK", "其他" };
        }
        return strTask;
    }

    public void setStrTask(String[] strTask) {
        this.strTask = strTask;
    }

}
